package com.runfig.producer.controller;

import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class IndexController {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @RequestMapping("/send")
    public String send(String msg ,String tag ) {


        rocketMQTemplate.syncSend("zhaowang:"+tag, msg);

//        Map<String,Object> map=new HashMap<>();
//
//        //用户自定义属性
//        map.put("age", 19);


      //  rocketMQTemplate.convertAndSend("10",msg,map);

//        rocketMQTemplate.syncSend("01", msg);
//        return "ok";

        //rocketMQTemplate.sendOneWay("03", msg);

//        rocketMQTemplate.syncSend("04", MessageBuilder.withPayload(msg).build(), 3000, 3);
//
//        rocketMQTemplate.asyncSend("02", msg, new SendCallback() {
//
//            @Override
//            public void onSuccess(SendResult sendResult) {
//                System.out.println("ok");
//            }
//
//            @Override
//            public void onException(Throwable e) {
//                System.out.println("sb");
//            }
//
//        });
        return "发送"+msg+"ok";
    }
}
